home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 400_01 / socketpp-1.5 / test / tnntp.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-06  |  757 b   |  46 lines

  1. #include <sockinet.h>
  2.  
  3. extern "C" void exit(int);
  4.  
  5. static int send_cmd(const char*, iosockstream&);
  6. static int get_text(istream&);
  7.  
  8. main()
  9. {
  10.     iosockinet     sio(sockbuf::sock_stream);
  11.     sockinetaddr sina("murdoch.acc.virginia.edu", "nntp", "tcp");
  12.  
  13.     sio->connect(sina);
  14.  
  15.     send_cmd(0, sio);
  16.     
  17.     send_cmd("HELP", sio); get_text(sio);
  18.     send_cmd("QUIT", sio);
  19. }
  20.  
  21. int send_cmd(const char* cmd, iosockstream& s)
  22. {
  23.     s << cmd << "\r\n";
  24.  
  25.     char buf[256];
  26.     s.getline(buf, 255);
  27.  
  28.     cout << buf << endl;
  29.  
  30.     if (buf[0] == '4' || buf[1] == '5') return 1;
  31.     return 0;
  32. }
  33.  
  34. int get_text(istream& s)
  35. {
  36.     char buf[256];
  37.     while (s.getline(buf, 255))
  38.         if (buf[0] == '.') {
  39.             if (buf[1] == '.') cout << buf+1 << endl;
  40.             else return 0;
  41.         }else
  42.             cout << buf << endl;
  43.     return 1;
  44. }
  45.         
  46.